package homework.mid_autumn_festival.collection_exercixe;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

public class CollectionDemo2 {
    public static void main(String[] args) {
        //Collection c = new HashSet();
        Collection c = new ArrayList();
        c.add(new Person(1,2));
        c.add(new Person(3,4));
        c.add(new Person(5,6));
        c.add(new Person(7,8));
        c.add(new Person(9,0));
        boolean b = c.add(new Person(1,2));
        System.out.println(b);//对于HashSet而言,是否重复取决于元素的equals结果

        //contains判断当前的集合是否包含给定元素o
        Person p = new Person(1, 2);
        boolean contains = c.contains(p);
        System.out.println(contains);//true

        //从当前集合中删除给定元素O的equals判断结果为true的元素
        //若存在重复元素也只删除第一次匹配上的元素
        boolean remove = c.remove(p);
        System.out.println("是否删除成功:"+remove);
        System.out.println(c);

    }
}
